//
//  ViewController.m
//  DropDownListProject
//
//  Created by 花若似相离 on 2018/3/15.
//  Copyright © 2018年 YangYang. All rights reserved.
//

#import "ViewController.h"
#import "PopoverView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavItem];
    [self setupUI];
}

-(void)setupUI
{
    UIButton *leftTopAddAction = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftTopAddAction setTitle:@"+" forState:UIControlStateNormal];
    leftTopAddAction.titleLabel.font = [UIFont systemFontOfSize:15];
    [leftTopAddAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [leftTopAddAction addTarget:self action:@selector(leftTopAddActionClicked:) forControlEvents:UIControlEventTouchUpInside];
    leftTopAddAction.layer.borderColor = [UIColor grayColor].CGColor;
    leftTopAddAction.layer.borderWidth = 0.3;
    leftTopAddAction.titleLabel.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:leftTopAddAction];
    [leftTopAddAction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(20);
        make.top.mas_equalTo(self.view.mas_top).offset(64 + 20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    
    
    UIButton *rightTopAddAction = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightTopAddAction setTitle:@"+" forState:UIControlStateNormal];
    rightTopAddAction.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightTopAddAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightTopAddAction addTarget:self action:@selector(rightTopAddActionClicked:) forControlEvents:UIControlEventTouchUpInside];
    rightTopAddAction.layer.borderColor = [UIColor grayColor].CGColor;
    rightTopAddAction.layer.borderWidth = 0.3;
    rightTopAddAction.titleLabel.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:rightTopAddAction];
    [rightTopAddAction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view.mas_right).offset(-20);
        make.top.mas_equalTo(self.view.mas_top).offset(64 + 20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    
    UIButton *leftBottomAddAction = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBottomAddAction setTitle:@"+" forState:UIControlStateNormal];
    leftBottomAddAction.titleLabel.font = [UIFont systemFontOfSize:15];
    [leftBottomAddAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [leftBottomAddAction addTarget:self action:@selector(leftBottomAddActionClicked:) forControlEvents:UIControlEventTouchUpInside];
    leftBottomAddAction.layer.borderColor = [UIColor grayColor].CGColor;
    leftBottomAddAction.layer.borderWidth = 0.3;
    leftBottomAddAction.titleLabel.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:leftBottomAddAction];
    [leftBottomAddAction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(20);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    
    UIButton *righttBottomAddAction = [UIButton buttonWithType:UIButtonTypeCustom];
    [righttBottomAddAction setTitle:@"+" forState:UIControlStateNormal];
    righttBottomAddAction.titleLabel.font = [UIFont systemFontOfSize:15];
    [righttBottomAddAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [righttBottomAddAction addTarget:self action:@selector(rightBottomAddActionClicked:) forControlEvents:UIControlEventTouchUpInside];
    righttBottomAddAction.layer.borderColor = [UIColor grayColor].CGColor;
    righttBottomAddAction.layer.borderWidth = 0.3;
    righttBottomAddAction.titleLabel.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:righttBottomAddAction];
    [righttBottomAddAction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view.mas_right).offset(-20);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    
    
    UIButton *centerAddAction = [UIButton buttonWithType:UIButtonTypeCustom];
    [centerAddAction setTitle:@"+" forState:UIControlStateNormal];
    centerAddAction.titleLabel.font = [UIFont systemFontOfSize:15];
    [centerAddAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [centerAddAction addTarget:self action:@selector(centerActionClicked:) forControlEvents:UIControlEventTouchUpInside];
    centerAddAction.layer.borderColor = [UIColor grayColor].CGColor;
    centerAddAction.layer.borderWidth = 0.3;
    centerAddAction.titleLabel.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:centerAddAction];
    [centerAddAction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX).offset(0);
        make.centerY.mas_equalTo(self.view.mas_centerY).offset(0);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
}

-(void)setupNavItem
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"list"] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarButtonItemAction)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightBarButtonItemAction:)];
}

-(void)leftBarButtonItemAction
{
    
}

-(void)centerActionClicked:(UIButton *)sender
{
    NSArray *actionArr = [self getPopActionArr];
    PopoverView *popView = [PopoverView popoverView];
//    popView.style = PopoverViewStyleDark;
    [popView showToView:sender withActions:actionArr withAlignmentStyle:PopoverViewAlignmentStyleCenter];
}

-(void)rightBarButtonItemAction:(UIBarButtonItem *)sender
{
    NSArray *actionArr = [self getPopActionArr];
    PopoverView *popView = [PopoverView popoverView];
    popView.style = PopoverViewStyleCustom;
    popView.viewColor = [UIColor colorWithHexString:@"#2B74CE"];
    popView.fontColor = [UIColor colorWithHexString:@"#ffffff"];
    [popView showToPoint:CGPointMake(ScreenWidth - 10, 64) withActions:actionArr withAlignmentStyle:0];
}

-(void)rightTopAddActionClicked:(UIButton *)sender
{
    NSArray *actionArr = [self getPopActionArr];
    PopoverView *popView = [PopoverView popoverView];
    popView.style = PopoverViewStyleDark;
    popView.showShade = YES;
    [popView showToView:sender withActions:actionArr withAlignmentStyle:0];
}

-(void)rightBottomAddActionClicked:(UIButton *)sender
{
    NSArray *actionArr = [self getPopActionArr];
    PopoverView *popView = [PopoverView popoverView];
    popView.style = PopoverViewStyleDark;
    [popView showToView:sender withActions:actionArr withAlignmentStyle:0];
}

-(void)leftTopAddActionClicked:(UIButton *)sender
{
    NSArray *actionArr = [self getPopActionArr];
    PopoverView *popView = [PopoverView popoverView];
    [popView showToView:sender withActions:actionArr withAlignmentStyle:0];
}

-(void)leftBottomAddActionClicked:(UIButton *)sender
{
    NSArray *actionArr = [self getPopActionArr];
    PopoverView *popView = [PopoverView popoverView];
    popView.showShade = YES;
    [popView showToView:sender withActions:actionArr withAlignmentStyle:0];
}

-(NSArray *)getPopActionArr
{
    NSArray *titleArr = @[@"创建群聊",@"加好友/群",@"扫一扫",@"面对面快传",@"付款",@"拍摄",@"高能舞室"];
    NSArray *imageArr = @[@"file",@"addFriend",@"scan",@"uploadFile",@"payment",@"camera",@"dance"];
    NSLog(@"titleArr.count = %ld,imageArr.count = %ld",titleArr.count,imageArr.count);
    
    NSMutableArray *popActionArr = [NSMutableArray new];
    for (NSInteger i = 0; i < titleArr.count; ++i) {
        NSString *titleString = titleArr[i];
        NSString *imageName = imageArr[i%imageArr.count];
        PopoverAction *popAction = [PopoverAction actionWithImage:[UIImage imageNamed:imageName] title:titleString handler:^(PopoverAction *action) {
            NSLog(@"点击了------%@-------",action.title);
            UIViewController *vc = [[UIViewController alloc] init];
            vc.navigationItem.title = action.title;
            vc.view.backgroundColor = [UIColor whiteColor];
            [self.navigationController pushViewController:vc animated:YES];
        }];
        [popActionArr addObject:popAction];
    }
    NSArray *resultArr = [NSArray arrayWithArray:popActionArr];
    NSLog(@"resultArr.count = %ld",resultArr.count);
    return resultArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
